home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / ex / ex8-2.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  748b  |  30 lines

  1. // ex8-2.c -- Use of an Iterator with container
  2. //            for objects of unknown class
  3.  
  4. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-2.c,v 3.0 90/05/15 22:46:14 kgorlen Rel $
  5.  
  6. #include "OrderedCltn.h"
  7. #include "Iterator.h"
  8. #include "String.h"
  9.  
  10. void listContainer(ostream& strm,Collection& cltn)
  11. {
  12. //  Iterator knows neither
  13. //  the actual class of cltn nor    
  14. //  the actual class of any Object in cltn
  15.     Iterator it(cltn);    
  16.     while (it++) strm << *it() << " ";    
  17. }
  18.  
  19. main()
  20. {
  21.     OrderedCltn symbols;
  22.     symbols.add(*new String("A"));
  23.     symbols.add(*new String("C"));
  24.     symbols.add(*new String("G"));
  25.     symbols.add(*new String("T"));
  26.  
  27.     listContainer(cout,symbols);
  28.     cout << endl;
  29. }
  30.